package com.qnbc.mystery.config;

import com.qnbc.mystery.config.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("/doc.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");


        registry.addResourceHandler("/uploadPic/**").addResourceLocations("file:/Users/gzj/Documents/workspace/mywork/GraduationDesign/7盲盒小程序 3.15/5.project/mystery_box_cn/picfile/");
        registry.addResourceHandler("/image/swiper/**").addResourceLocations("file:/Users/gzj/Documents/workspace/mywork/GraduationDesign/7盲盒小程序 3.15/5.project/mystery_box_cn/picfile/swiperImgs/");
        registry.addResourceHandler("/image/bigType/**").addResourceLocations("file:/Users/gzj/Documents/workspace/mywork/GraduationDesign/7盲盒小程序 3.15/5.project/mystery_box_cn/picfile/bigTypeImgs/");
        registry.addResourceHandler("/image/product/**").addResourceLocations("file:/Users/gzj/Documents/workspace/mywork/GraduationDesign/7盲盒小程序 3.15/5.project/mystery_box_cn/picfile/productImgs/");
        registry.addResourceHandler("/image/productSwiperImgs/**").addResourceLocations("file:/Users/gzj/Documents/workspace/mywork/GraduationDesign/7盲盒小程序 3.15/5.project/mystery_box_cn/picfile/productSwiperImgs/");
        registry.addResourceHandler("/image/productIntroImgs/**").addResourceLocations("file:/Users/gzj/Documents/workspace/mywork/GraduationDesign/7盲盒小程序 3.15/5.project/mystery_box_cn/picfile/productIntroImgs/");
        registry.addResourceHandler("/image/productParaImgs/**").addResourceLocations("file:/Users/gzj/Documents/workspace/mywork/GraduationDesign/7盲盒小程序 3.15/5.project/mystery_box_cn/picfile/productParaImgs/");
        super.addResourceHandlers(registry);
    }

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login", "/user/openId", "/user/register", "/**/export", "/**/import", "/file/**", "/uploadPic/**", "/news/**", "/notice/**", "/comment/**", "/role/**", "/product/**", "/bigtype/**", "/appletuser/wxlogin", "/weixinpay/**", "/collect/**", "/image/**", "/AboutMe/**", "/config/**", "/alipay/**","/mystery/area/**","/address/**","/productSwiperImage/**","/boxInfo/**","/mystery/set/**")
                .excludePathPatterns("/doc.html", "/swagger**/**", "/webjars/**","/*.html","/v2/**");
        super.addInterceptors(registry);
    }

    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }

}
